package com.teacher.mobile.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.teacher.common.CommonResult;
import com.teacher.pojo.dto.carpoolPost.*;
import com.teacher.pojo.vo.carpoolPost.CarpoolPostVo;
import com.teacher.security.entity.annotation.WhiteApi;
import com.teacher.service.ICarpoolPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jiangzhuohang
 * @since 2024-03-14
 */
@RestController
@RequestMapping("/carpoolPost")
@Api(tags = "拼车帖子接口")
public class CarpoolPostController {
    @Autowired
    private ICarpoolPostService iCarpoolPostService;


    @WhiteApi
    @ApiOperation("获取拼车贴列表(分页)")
    @PostMapping("/getCarpoolPost")
    public CommonResult getCarpoolPost(@RequestBody CarpoolPostDto pageVo){
        IPage<CarpoolPostVo> carpoolPostPageData = iCarpoolPostService.getCarpoolPostPageData(pageVo);
        return CommonResult.success(carpoolPostPageData);
    }

    @ApiOperation("获取 自己的 拼车贴列表(分页)只要传最早或最晚时间就好了")
    @PostMapping("/getOwnCarpoolPost")
    public CommonResult getOwnCarpoolPost(@RequestBody OwnCarpoolDto pageVo){
        IPage<CarpoolPostVo> carpoolPostPageData = iCarpoolPostService.getOwnCarpoolPost(pageVo);
        return CommonResult.success(carpoolPostPageData);
    }

    @ApiOperation("小程序获取拼车贴列表  废弃")
    @GetMapping("/getCarpoolList")
    public CommonResult getCarpoolList(SelectCarpoolList selectCarpoolList){
        return iCarpoolPostService.getCarpoolList(selectCarpoolList);

    }


    @WhiteApi
    @ApiOperation("小程序根据帖子id获取拼车贴详情")
    @GetMapping("/getCarpoolInfoById")
    public CommonResult getCarpoolInfoById(Long id){
        return iCarpoolPostService.getCarpoolInfoById(id);

    }

    @ApiOperation("申请拼车")
    @GetMapping("/requestCarpool")
    public CommonResult requestCarpool(RequestCarpoolDto requestCarpoolDto){
        return iCarpoolPostService.requestCarpool(requestCarpoolDto);

    }

    @PostMapping("examineCarpoolPost")
    @ApiOperation("审核拼车 ")
    public CommonResult examineCarpoolPost(@RequestBody ExamineCarpoolPostDto dto) {
        return iCarpoolPostService.examineCarpoolPost(dto);
    }

    @GetMapping("endCarpoolPost")
    @ApiOperation("手动截止拼车 ")
    public CommonResult endCarpoolPost(Long carpoolPostId) {
        return iCarpoolPostService.endCarpoolPost(carpoolPostId);
    }

    @GetMapping("cancelCarpoolPost")
    @ApiOperation("取消拼车 ")
    public CommonResult cancelCarpoolPost(Long carpoolPostId) {
        return iCarpoolPostService.cancelCarpoolPost(carpoolPostId);
    }


    @PostMapping("addCarpoolPost")
    @ApiOperation("小程序添加拼车贴(后台不允许添加) ")
    public CommonResult addCarpoolPost(@RequestBody CarpoolPostAddDto dto) {
        return iCarpoolPostService.addCarpoolPost(dto);
    }

    @DeleteMapping("/deleteCarpoolPostById")
    @ApiOperation("通过拼车贴 id批量删除拼车贴 ")
    public CommonResult deleteCarpoolPostById(@RequestBody List<Long> list) {
        return  iCarpoolPostService.deleteCarpoolPost(list);
    }
    @PutMapping("/updateCarpoolPostById")
    @ApiOperation("通过拼车贴id修改拼车贴 ")
    public CommonResult updateCarpoolPostById(@RequestBody CarpoolPostUpdateDto updateDto) {
        return iCarpoolPostService.updateCarpoolPost(updateDto);
    }
}

